import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)
let routerList = [];

function importAll(r) {
  console.log(r.keys())
  r.keys().forEach(element => {
    routerList.push(r(element).default)
  });
}

importAll(require.context('./', true, /\.router\.js/))
console.log(routerList)

const routes = [
  ...routerList,
  {
    path: '/',
    name: 'Home',
    component: Home,
    beforeEnter: (to, from, next) => {
      console.log(window.screen.width);
      if (window.screen.width < 500) {
        next({ name: 'HomePhone' })
      }
      next()
    }
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router